<?php


namespace app\common\models;


use app\common\caches\UserSignCache;
use app\common\traits\BaseModelOptionTrait;
use think\Model;

class UserSign extends Model
{
    use BaseModelOptionTrait;

    protected $table = 'xiangji_user_signs';
    // 自动维护时间戳
    protected $autoWriteTimestamp = true;

    const NOT_SIGN = 0;
    const SINGLE_SIGN = 1;
    const DOUBLE_SIGN = 2;

    public static function onAfterInsert($sign)
    {
        // 清除今日签到状态
        UserSignCache::flushUserSignData($sign->user_id);
    }

    // 该签到的所属用户
    public function user()
    {
        $this->belongsTo(User::class);
    }
}
